<template>
   <a-layout-header :class="[fixHeader && 'ant-header-fixedHeader', layout === 'side' ? (sidebarOpened ? 'ant-header-side-opened' : 'ant-header-side-closed') : null, theme, 'global-header', isMobile ? 'no-pad-lef' : '' ]">
    <!-- <div class="logo">
      <router-link to="/">
        <img src="static/img/logo.png" alt="">
        <h1 class="animated fadeIn">{{systemName}}</h1>
      </router-link>
    </div> -->
    <div :class="['global-header-wide', layout]" id="layout">
      <router-link v-if="!isMobile && layout === 'head'" to="/" :class="['logo', isMobile ? null : 'pc', theme]">
         <img width="32" src="static/img/logo.png"  alt=""/>	11	         <img width="32" src="static/img/logo.png"  alt=""/>
        <h1 v-if="!isMobile">{{systemName}}</h1>	12	+        <h1>{{systemName}}</h1>
       </router-link>
      <a-divider v-if="isMobile" type="vertical" />
      <a-icon v-if="layout === 'side'" class="trigger" :type="collapsed ? 'menu-unfold' : 'menu-fold'" @click="toggleCollapse"/>
      <div v-if="layout === 'head'" class="global-header-menu">
        <i-menu style="height: 64px; line-height: 64px;" class="system-top-menu" :theme="theme" mode="horizontal" :menuData="menuData" @select="onSelect"/>
      </div>
      <div :class="['global-header-right', theme]">
        <header-avatar class="header-item"/>
        <!-- <Icon type="global"/> -->
        <lang-select />
      </div>

      <!-- <a-tabs v-if="layout === 'side'" :defaultActiveKey="defaultKey" style="display:inline-block; vertical-align:top" @change="changeMenu">
        <a-tab-pane v-for="item in menu" :key="item.id||1" v-show="!item.hidden" :tab="item.name"></a-tab-pane>
      </a-tabs> -->
    </div>
  </a-layout-header>
</template>

<script>
import HeaderAvatar from './HeaderAvatar'
import IMenu from '@/components/menu/menu'
import { mapState } from 'vuex'
import constRouter from '@/router/constRouter'
import langSelect from './langSelect'

export default {
  name: 'GlobalHeader',
  components: {IMenu, HeaderAvatar, langSelect},
  props: ['collapsed', 'menuData'],
  data () {
    return {
      menu: [],
      defaultKey: '1'
    }
  },
  computed: {
    ...mapState({
      isMobile: state => state.setting.isMobile,
      layout: state => state.setting.layout,
      systemName: state => state.setting.systemName,
      sidebarOpened: state => state.setting.sidebar.opened,
      fixHeader: state => state.setting.fixHeader,
      mapData: state => state.setting.mapData,
      fullMenu: state => state.setting.fullMenu
    }),
    theme () {
      return this.layout === 'side' ? 'light' : this.$store.state.setting.theme
    }
  },
  created () {
    this.menu = constRouter
    this.menu.forEach(v => {
      if (this.$route.path.match(v.path)) {
        this.defaultKey = v.id
        this.changeMenu(v.id, true)
      }
    })
  },
  methods: {
    toggleCollapse () {
      this.$emit('toggleCollapse')
    },
    onSelect (obj) {
      this.$emit('menuSelect', obj)
    },
    redirect (param) {
      if (param[0].children && param[0].children.length > 0) {
        this.redirect(param[0].children)
      } else {
        this.$router.push(param[0].path)
      }
    },
    changeMenu (key, disChange) {
      // if (key === '1') {
      //   this.$store.dispatch('setting/setMenu', { menuData: this.fullMenu })
      //   this.$router.push('/home')
      // } else {
      //   const menuData = this.mapData[key]
      //   this.$store.dispatch('setting/setMenu', { menuData })
      //   if (!disChange) {
      //     this.redirect(menuData)
      //   }
      // }
    }
  }
}
</script>

<style lang="less">
  #layout{
    .ant-tabs-ink-bar {
      bottom: auto;
      top: 1px;
      color: red;
    }
    .ant-tabs-bar.ant-tabs-top-bar {
      border: none;
    }
    .ant-tabs-nav-container {
      line-height: 2.5
    }
  }
  .trigger {
    font-size: 20px;
    line-height: 64px;
    padding: 0 24px;
    cursor: pointer;
    transition: color .3s;
  }
  .header-item{
    padding: 0 19px;
    display: inline-block;
    height: 100%;
    cursor: pointer;
    vertical-align: middle;
    i{
      font-size: 16px;
      color: rgba(0,0,0,.65);
    }
  }
  .global-header{
    padding: 0 12px 0 0;
    -webkit-box-shadow: 0 1px 4px rgba(0,21,41,.08);
    box-shadow: 0 1px 4px rgba(0,21,41,.08);
    position: relative;
    width: 100%;
    &.light{
      background: #fff;
    }
    &.dark{
      background: #001529;
    }
    .global-header-wide{
      &.head{
        padding: 0 24px;
      }
      &.side{
      }
      .logo {
        height: 64px;
        line-height: 58px;
        vertical-align: top;
        display: inline-block;
        padding: 0 12px 0 24px;
        cursor: pointer;
        font-size: 20px;
        &.pc{
          padding: 0 12px 0 0;
        }
        img {
          display: inline-block;
          vertical-align: middle;
        }
        h1{
          display: inline-block;
          font-size: 16px;
        }
        &.dark h1{
          color: #fff;
        }
      }
      .global-header-menu{
        display: inline-block;
      }
      .global-header-right{
        position: absolute;
        right: 0;
        top: 0;
        padding-right: 20px;
        // float: right;
        &.dark{
          color: #fff;
          i{
            color: #fff;
          }
        }
      }
    }
  }
  .ant-header-fixedHeader {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 15;
    // width: 100%;
    transition: width .2s;

    &.ant-header-side-opened {
      width: 100%;
      padding-left: 254px;
    }

    &.ant-header-side-closed {
      width: 100%;
      padding-left: 80px;
    }
  }
  .no-pad-lef{
    padding-left: 0 !important;
  }
</style>
